@echo off
echo ================================
echo 卸载考试系统Windows服务
echo ================================

:: 检查管理员权限
net session >nul 2>&1
if errorlevel 1 (
    echo 错误: 需要管理员权限才能卸载Windows服务
    echo 请右键选择"以管理员身份运行"
    pause
    exit /b 1
)

:: 设置变量
set PROJECT_DIR=%~dp0
set BACKEND_DIR=%PROJECT_DIR%backend

echo 创建服务卸载脚本...
cd /d "%BACKEND_DIR%"
(
echo const Service = require('node-windows'^).Service;
echo const path = require('path'^);
echo.
echo // 创建服务对象
echo const svc = new Service({
echo   name: 'ExamSystemBackend',
echo   script: path.join(__dirname, 'src', 'server.ts'^)
echo }^);
echo.
echo // 监听卸载事件
echo svc.on('uninstall', function(^) {
echo   console.log('服务卸载成功');
echo }^);
echo.
echo // 卸载服务
echo svc.uninstall(^);
) > uninstall-service.js

echo 卸载Windows服务...
node uninstall-service.js

echo.
echo ================================
echo Windows服务卸载完成！
echo ================================
pause
